package com.chinasofti.info_manager.service;

import com.chinasofti.info_manager.dao.TeacherDao;
import com.chinasofti.info_manager.domain.Teacher;

public class TeacherService {
    TeacherDao Dao = new TeacherDao();


    public void deleteTeacherById(String id){
        Dao.deleteTeacherById(id);
    }

    //判断老师号是否存在
    public boolean isExists(String id){ //返回值weitrue代表 id不存在
        boolean exists = false;
        //判断数组中是否有这个id
        int index = Dao.getIndex(id);
        if(index == -1){
            exists = true; //不存在
        }
        return exists;
    }

    public boolean addTeacher(Teacher tea) {
        return Dao.addTeacher(tea);
    }

    public Teacher[] findAllTeacher() {
        Teacher[] allTeacher = Dao.findAllTeacher();
        boolean flag = false;//做一个开关；allStudents有值怎返回；allStudents没有值返回null
        for (int i=0;i<allTeacher.length;i++){
            Teacher tea = allTeacher[i];
            if(tea != null){
                flag = true;
                break;
            }
        }
        if(flag){
            return allTeacher;
        }else {
            return null;
        }

    }

    /**
     *
     * @param updateId
     * @param newTea 更新对象
     * @return
     */
    public boolean updateTeacher(String updateId, Teacher newTea) {
        Dao.updateTeacher(updateId,newTea);
        return true;
    }
}
